/*
* $Id: JournalStore.java 292 2011-03-24 21:08:17Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2010 by Volokitin Alexey
* All rights reserved
*
*/
package apiary.db;

import java.io.*;
import java.util.Date;

/**
 * Common family inspection database
 * @author lexus
 */
public class JournalStore extends DBStore
{
    /**
     * Container of inspection records
     * @author lexus
     */
    public class JournalRecord extends DBRecord
    {
//-----------------------------Status queen bee---------------------------------
        public static final int IS_DEFAULT = 0;
	public static final int IS_LOOK = 1;
	public static final int IS_ABSENCE = 2;
	public static final int IS_FETAL = 3;
//-------------------------------Diseases bees----------------------------------
        public static final int DISEASE_HEALTHY = 0;
	public static final int DISEASE_AFB = 1;
        public static final int DISEASE_EFB = 2;
        public static final int DISEASE_PFB = 3;
	public static final int DISEASE_VARROA = 4;
	public static final int DISEASE_ACARINE = 5;
	public static final int DISEASE_NOSEMA = 6;
	public static final int DISEASE_CHALKBROOD = 7;
	public static final int DISEASE_STONEBROOD = 8;
	public static final int DISEASE_ABPV = 8;
        public static final int DISEASE_MILK = 9;
        public static final int DISEASE_PBV = 10;
	public static final int DISEASE_BQCV = 11;
        public static final int DISEASE_CPV = 12;
        public static final int DISEASE_CWV = 13;
	public static final int DISEASE_DWV = 14;
        public static final int DISEASE_SBV = 15;
        public static final int DISEASE_CCD = 16;
	public static final int DISEASE_GAFN = 17;
        public static final int DISEASE_SALMON = 18;
	public static final int DISEASE_SEPT = 19;
        public static final int DISEASE_COLI = 20;
	public static final int DISEASE_CITRO = 21;
        public static final int DISEASE_SPIRO = 22;
	public static final int DISEASE_FILO = 23;
        public static final int DISEASE_MELONOZ = 24;
	public static final int DISEASE_AMEBA = 25;
        public static final int DISEASE_CRITI = 26;
	public static final int DISEASE_MERM = 27;
        public static final int DISEASE_PIE = 28;
        public static final int DISEASE_EAP = 29;
	public static final int DISEASE_GREG = 30;
        public static final int DISEASE_SEN = 31;

        /** Identificator of common inspection */
        public int idJournal;
        /** Identificator of family */
        public int idFamily;
        /** Date inspection */
        public Date date;
        /** Count frame */
        public int frame;
        /** Strength of family */
        public int strength;
        /** Status queen bee */
        public int is_queen_bee;
        /** Count wax*/
        public int wax;
        /** Amount ambrosia */
        public int ambrosia;
        /** Number of evacuated honey */
        public int evacuation;
        /** number of feeding */
        public int dieting;
        /** Type disease */
        public int disease;
        /** Note for inspection */
        public String noteJournal;
        /** Identificator user's fields */
        public int idRecord;

        /**
         * Constructor
         */
        public JournalRecord() {
            date = new Date();
            noteJournal = new String();
        }

        /**
         * Gets byte array of record
         * @return byte array
         */
        public byte[] getData() {
             try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                DataOutputStream dos = new DataOutputStream(baos);
                dos.writeInt(idJournal);
                dos.writeInt(idFamily);
                dos.writeLong(date.getTime());
                dos.writeInt(frame);
                dos.writeInt(strength);
                dos.writeInt(is_queen_bee);
                dos.writeInt(wax);
                dos.writeInt(ambrosia);
                dos.writeInt(evacuation);
                dos.writeInt(dieting);
                dos.writeInt(disease);
                dos.writeUTF(noteJournal);
                dos.writeInt(idRecord);
                return baos.toByteArray();
            } catch (IOException ex) {}
            return null;
        }

        /**
         * Sets byte array record.
         * Array will be parsed and all fields of it will be filled
         * @param dis data input stream
         */
        public void setData(DataInputStream dis) throws IOException{
                idJournal = dis.readInt();
                idFamily = dis.readInt();
                date.setTime(dis.readLong());
                frame = dis.readInt();
                strength = dis.readInt();
                is_queen_bee = dis.readInt();
                wax = dis.readInt();
                ambrosia = dis.readInt();
                evacuation = dis.readInt();
                dieting = dis.readInt();
                disease = dis.readInt();
                noteJournal = dis.readUTF();
                idRecord = dis.readInt();
        }
    }

    /**
     * Constructor
     */
    public JournalStore() {
        super("db_journal");
    }

    /**
     * Gets new record
     * @return new record
     */
    public DBRecord getRecord() {
        return new JournalRecord();
    }
}
